function preconditioner = calculatePreconditioner2D(n, nonTrivial)

    %calculatePreconditioner2D Summary of this function goes here
    %   Detailed explanation goes here

    m=2*n+1;
    preconditioner=ones(m,n+1);
    c=2*(n+1)/(m*n);
    for k=-n:n
        if k==0
            preconditioner(k+n+1,:)=1/m^2;
        else
            preconditioner(k+n+1,:)=(abs(k*c));
        end
    end
    if nonTrivial
        options = optimset('Display','final','FunValCheck','off','MaxIter',50000,'MaxFunEvals',50000);
        [preconditioner,fval,exitflag,output] = ...
            fminsearch(@(x)calculateConditionNumber(x,1.e-12,20,1),preconditioner,options);
        fprintf('fval = %f, exitflag = %d, output.algorithm = %s, output.funcCount = %d, output.iterations = %d, output.message = %s\n',...
            fval,exitflag,output.algorithm,output.funcCount,output.iterations,output.message);
    end

end

